package com.tyqx.hashchainbiz.service.impl;

import com.tyqx.hashchainbean.module.JZTCodeCirculation;
import com.tyqx.hashchainbean.vo.*;
import com.tyqx.hashchainbiz.service.JZTCodeCirculationService;
import com.tyqx.hashchaindao.mapper.JZTCodeCirculationMapper;
import com.tyqx.hashchaindao.mapper.JZTGS1RelationshipMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("jztCodeCirculationService")
public class JZTCodeCirculationServiceImpl implements JZTCodeCirculationService {

    @Resource
    private JZTCodeCirculationMapper jztCodeCirculationMapper;

    @Resource
    private JZTGS1RelationshipMapper jztgs1RelationshipMapper;

    @Override
    public Integer addJZTCodeCirculation(JZTCodeCirculation jztCodeCirculation) {
        return jztCodeCirculationMapper.addJZTCodeCirculation(jztCodeCirculation);
    }

    @Override
    public List<JZTCodeCirculationVO> getJZTCodeCirculationByTraceabilityCode(List<String> traceabilityCodes,String userName) {
        return jztCodeCirculationMapper.getJZTCodeCirculationByTraceabilityCode(traceabilityCodes,userName);
    }

    @Override
    public List<JZTCodeCirculationAndGS1VO> getJZTCodeCirculationAndGS1ByTraceabilityCode(List<String> traceabilityCodes) {

        List<JZTCodeCirculationAndGS1VO> jztCodeCirculationAndGS1VOList=jztCodeCirculationMapper.getJZTCodeCirculationAndGS1ByTraceabilityCode(traceabilityCodes);
        for (int i=0;i<jztCodeCirculationAndGS1VOList.size();i++){
            JZTCodeCirculationAndGS1VO jztCodeCirculationAndGS1VO=jztCodeCirculationAndGS1VOList.get(i);
            String traceabilityCode=jztCodeCirculationAndGS1VO.getTraceabilityCode();
            List<JZTGS1RelationshipVO> jztgs1RelationshipVOList=jztgs1RelationshipMapper.getJZTGS1RelationshipListByTraceabilityCode(traceabilityCode);
            String ssccCode="";
            if(jztgs1RelationshipVOList.size()>0){
                JZTGS1RelationshipVO jztgs1RelationshipVO=jztgs1RelationshipVOList.get(0);
                ssccCode=jztgs1RelationshipVO.getSsccCode();
            }
            jztCodeCirculationAndGS1VO.setSsccCode(ssccCode);
        }

        return jztCodeCirculationAndGS1VOList;
    }

    @Override
    public List<JZTCodeCirculationAndGS1VO> grantGetJZTCodeCirculationAndGS1ByTraceabilityCode(List<String> traceabilityCodes, String userName) {
        List<JZTCodeCirculationAndGS1VO> jztCodeCirculationAndGS1VOList=jztCodeCirculationMapper.grantGetJZTCodeCirculationAndGS1ByTraceabilityCode(traceabilityCodes,userName);
        for (int i=0;i<jztCodeCirculationAndGS1VOList.size();i++){
            JZTCodeCirculationAndGS1VO jztCodeCirculationAndGS1VO=jztCodeCirculationAndGS1VOList.get(i);
            String traceabilityCode=jztCodeCirculationAndGS1VO.getTraceabilityCode();
            List<JZTGS1RelationshipVO> jztgs1RelationshipVOList=jztgs1RelationshipMapper.getJZTGS1RelationshipListByTraceabilityCode(traceabilityCode);
            String ssccCode="";
            if(jztgs1RelationshipVOList.size()>0){
                JZTGS1RelationshipVO jztgs1RelationshipVO=jztgs1RelationshipVOList.get(0);
                ssccCode=jztgs1RelationshipVO.getSsccCode();
            }
            jztCodeCirculationAndGS1VO.setSsccCode(ssccCode);
        }

        return jztCodeCirculationAndGS1VOList;
    }

    @Override
    public List<JZTCodeCirculationVO> getJZTJZTCodeCirculationByCode(String traceabilityCode) {
        return jztCodeCirculationMapper.getJZTJZTCodeCirculationByCode(traceabilityCode);
    }


    @Override
    public Integer insertBatch(List<JZTCodeCirculation> jztCodeCirculationList) {
        return jztCodeCirculationMapper.insertBatch(jztCodeCirculationList);
    }
}
